using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using PIT.Labs.SharePoint.Logger;
using PIT.Labs.SharePoint.Extensions.Helper;

namespace PIT.Labs.ProjectRepository.WebParts.ListRandomizerWebPart.Features.ListRandomizerFeature
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>

    [Guid("cc1ab705-cfce-490d-8150-82791442be57")]
    public class ListRandomizerFeatureEventReceiver : SPFeatureReceiver
    {

        private readonly Guid timerFeatureGUID = new Guid("8a443437-ca36-4d79-be5d-35f2acfd8a81");

        /// <summary>
        /// Handles the event that is raised after a Feature is activated. In this case: Checks if the Randomizer Timer is running.
        /// </summary>
        /// <param name="properties">The properties of the event.</param>
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;
            if (site == null)
                throw new ArgumentNullException("site");

            if (site.WebApplication.Features[timerFeatureGUID] == null)
            {
                SPLogger logger = new SPLogger();
                logger.Log(NLog.LogLevel.Warn, new SPException(SPUtilityHelper.GetLocalizedString("TIMER_NOT_ACTIVATED", ListRandomizerWebPart.ListRandomizerWebPart.RESOURCES_FILE)), true);
            }
        }


        // Uncomment the method below to handle the event raised before a feature is deactivated.

        //public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised after a feature has been installed.

        //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised before a feature is uninstalled.

        //public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        //{
        //}

        // Uncomment the method below to handle the event raised when a feature is upgrading.

        //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
        //{
        //}
    }
}
